#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
vector<LL>g[maxn];
LL vis[maxn];
LL a,b;
bool dfs(LL u,LL fa){
     ///vis[u]=1;
     bool flag=0;
     for(LL i=0;i<g[u].size();i++){
         LL v=g[u][i];
         if(v==fa) continue;
         if(v==b){
            vis[v]=2;
            return 1;
         }
         if(vis[v]==0){
            flag=dfs(v,u);
            if(flag==0) vis[v]=1;
            else vis[v]=2;
         }
     }
     if(flag){
        vis[u]=2;return 1;
     }
     else{
        vis[u]=1;return 0;
     }
}
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL t;cin>>t;
   while(t--){
      LL n,m;cin>>n>>m>>a>>b;
      for(LL i=0;i<n+10;i++) g[i].clear(),vis[i]=0;
      for(LL i=1;i<=m;i++){
          LL u,v;cin>>u>>v;
          g[u].push_back(v);
          g[v].push_back(u);
      }
      dfs(a,-1);
      for(LL i=1;i<=n;i++){
        cout<<vis[i]<<" ";
      }
      LL sum1=0;LL sum2=0;
      for(LL i=1;i<=n;i++){
         if(vis[i]==1){
            sum1++;
         }
         else if(vis[i]==0){
            sum2++;
         }
      }
      cout<<sum1*sum2<<"\n";
   }
   return 0;
}
